<html>
<head><meta charset="utf-8"><title>Are functionIds unique per Crate? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html">Are functionIds unique per Crate?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221366748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366748">(Jan 01 2021 at 20:11)</a>:</h4>
<p>Hi, </p>
<p>I noticed that ModuleId was defined as:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">ModuleId</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">krate</span>: <span class="nc">CrateId</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">local_id</span>: <span class="nc">LocalModuleId</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>and FunctionId was </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">FunctionId</span><span class="p">(</span><span class="n">salsa</span>::<span class="n">InternId</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>In this method: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/item_scope.rs#L357">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/item_scope.rs#L357</a></p>
<p>I think we are able to get the CrateID from just the FunctionID, does this mean that FunctionId's are unique across crates? And it is only true while Crates are processed sequentially?</p>



<a name="221366789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366789">(Jan 01 2021 at 20:12)</a>:</h4>
<p>FunctionIds are unique globally</p>



<a name="221366817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366817">(Jan 01 2021 at 20:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Are.20functionIds.20unique.20per.20Crate.3F/near/221366789">said</a>:</p>
<blockquote>
<p>FunctionIds are unique globally</p>
</blockquote>
<p>Ah so if you wanted to process the dependencies for a crate in parallel, this would need to change? Or you would maybe have a LocalFunctionId and FunctionId like ModuleId?</p>



<a name="221366818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366818">(Jan 01 2021 at 20:13)</a>:</h4>
<p>Or maybe it will always be this way?</p>



<a name="221366875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366875">(Jan 01 2021 at 20:14)</a>:</h4>
<p>why would it need to change?</p>



<a name="221366901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366901">(Jan 01 2021 at 20:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Are.20functionIds.20unique.20per.20Crate.3F/near/221366875">said</a>:</p>
<blockquote>
<p>why would it need to change?</p>
</blockquote>
<p>I thought it was a blocker for processing dependencies in parallel?</p>



<a name="221366927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366927">(Jan 01 2021 at 20:16)</a>:</h4>
<p>Hmm or maybe that would not matter for incremental compilation as much, as it would only help on the first compilation</p>



<a name="221366977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366977">(Jan 01 2021 at 20:16)</a>:</h4>
<p>I don't see why it would be a blocker for that. FunctionIds aren't guaranteed to be in any kind of sequential order</p>



<a name="221366997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221366997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221366997">(Jan 01 2021 at 20:17)</a>:</h4>
<p>they are interned IDs referring to the location of the function, i.e. the ID of the container plus the index in the container</p>



<a name="221367008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367008">(Jan 01 2021 at 20:18)</a>:</h4>
<p>the interning is synchronized, but it's very fast</p>



<a name="221367057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367057">(Jan 01 2021 at 20:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Are.20functionIds.20unique.20per.20Crate.3F/near/221366977">said</a>:</p>
<blockquote>
<p>I don't see why it would be a blocker for that. FunctionIds aren't guaranteed to be in any kind of sequential order</p>
</blockquote>
<p>Oh my thought process was that if the FunctionID is unique globally, then you cannot process two crates at the same time. Because then you may not have the functionIds be synchronised. </p>
<p>Hmm can you see where my logic fails?</p>



<a name="221367126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367126">(Jan 01 2021 at 20:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Are.20functionIds.20unique.20per.20Crate.3F/near/221367008">said</a>:</p>
<blockquote>
<p>the interning is synchronized, but it's very fast</p>
</blockquote>
<p>Oh, so the processing of dependencies will be parallel, but the IDs will be given out by the Interner which will guarantee that each Crate gets a unique FunctionID? And this would not be a bottleneck because the internet is fast?</p>



<a name="221367133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367133">(Jan 01 2021 at 20:20)</a>:</h4>
<p>yes</p>



<a name="221367161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367161">(Jan 01 2021 at 20:21)</a>:</h4>
<p>Okay got it, thanks for explaining!</p>



<a name="221367401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Are%20functionIds%20unique%20per%20Crate%3F/near/221367401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Are.20functionIds.20unique.20per.20Crate.3F.html#221367401">(Jan 01 2021 at 20:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="369769">kev</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Are.20functionIds.20unique.20per.20Crate.3F/near/221366927">said</a>:</p>
<blockquote>
<p>Hmm or maybe that would not matter for incremental compilation as much, as it would only help on the first compilation</p>
</blockquote>
<p>What I said here is not entirely true when I think it through, because external dependencies once downloaded would not change but if you are in a workspace then I think parallel processing would help since all crates in the workspace have an _equal_ chance of being changed.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>